import matplotlib.pyplot as plt
import numpy as np
from scipy import signal


N = 4
xn = np.array([1, 1, 1, 1])
Omiga = np.linspace(-2 * np.pi, 2 * np.pi, 512)
N1 = len(Omiga)
w = np.zeros((N, N1), dtype=complex)

for k1 in range(N):
    for k2 in range(N1):
        w[k1, k2] = np.exp(-1j * k1 * Omiga[k2])

spectrum = np.dot(xn, w)

plt.rcParams['font.sans-serif'] = ['SimHei']  # 加上这一句就能在图表中显示中文
plt.rcParams['axes.unicode_minus'] = False  # 用来正常显示负号

plt.subplot(2, 1, 1)
plt.plot(Omiga, abs(spectrum))
plt.title('幅度谱')


plt.subplot(2, 1, 2)
plt.plot(Omiga, np.angle(spectrum))
plt.ylabel('相位谱')

plt.show()
